package com.wgu.modules.web;

import com.wgu.common.global.Result;
import com.wgu.common.group.AddGroup;
import com.wgu.common.utils.ValidatorUtils;
import com.wgu.modules.service.UserService;
import com.wgu.modules.web.vo.UserVO;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户模块
 * @Author: w
 * @Date: 2019/6/24 15:41
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 新增用户
     * @param userVO
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody UserVO userVO){
        //验证
        ValidatorUtils.validateEntity(userVO, AddGroup.class);
        userService.save(userVO);
        return Result.ok();
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestParam Long id){
        userService.delete(id);
        return Result.ok();
    }

    @GetMapping("/list")
    public Result list(Pageable pageable){
        return Result.ok(userService.list(pageable));
    }
}
